﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.BusinessLogic;
using CMS.BaseEntity;
using CMS.Extends;
using System.Data;

namespace CMS
{
    public partial class Authentication : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            User user = new User();
            user.UserName = txtUserName.Text;
            user.Password = Library.GennerateToMD5(txtPassword.Text);
            if (UserLogic.Authenticate(user))
            {
                DataTable dt = UserLogic.GetUserLogin(user);
                DataRow dr = dt.Rows[0];
                Session["IsLogined"] = true;
                Session["UserId"] = dr["UserId"];
                Session["UserName"] = dr["UserName"];
                Session["Role"] = dr["Role"];

                Response.Redirect("Default.aspx");
            }
        }
    }
}